package org.giovanolli.mumi.controller.business;

import org.giovanolli.mumi.controller.AbstractController;
import org.giovanolli.mumi.controller.AbstractModel;
import org.giovanolli.mumi.entities.Phone;
import org.giovanolli.mumi.entities.filter.PhoneFilter;
import org.giovanolli.mumi.service.PhoneService;
import org.giovanolli.mumi.service.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

@Controller("phoneController")
public class PhoneController extends AbstractController<Phone> {

	@Autowired
	private PhoneService service;

	@Autowired
	private PhoneModel model;

	@Override
	protected void bindEntityToModel() {
		Phone editedPhone = model.getEditedEntity();
		model.setCountryCode(editedPhone.getCountryCode());
		model.setAreaCode(editedPhone.getAreaCode());
		model.setPhoneNumber(editedPhone.getPhoneNumber());
		model.setComment(editedPhone.getComment());
	}

	@Override
	protected void bindModelToEntity() {
		Phone editedPhone = model.getEditedEntity();
		editedPhone.setCountryCode(model.getCountryCode());
		editedPhone.setAreaCode(model.getAreaCode());
		editedPhone.setPhoneNumber(model.getPhoneNumber());
		editedPhone.setComment(model.getComment());
	}

	protected Class<Phone> getEntityClass() {
		return Phone.class;
	}

	@Override
	protected AbstractModel<Phone> getModel() {
		return model;

	}

	@Override
	protected Service<Phone> getService() {
		return service;
	}

	public void init() {
		super.init();
		model.setFilter(new PhoneFilter());
	}
}
